package bigdata.api.ticketbiz.service;

import bigdata.api.ticketbiz.SaleType;
import bigdata.api.ticketbiz.model.*;
import bigdata.api.ticketbiz.request.TicketbizRequestData;
import bigdata.api.ticketbiz.response.TicketbizResponse;
import bigdata.propertiesobj.TicketbizProperties;
import com.google.gson.reflect.TypeToken;
import common.utils.gsonutil.GsonUtil;
import org.springframework.stereotype.Service;
import pub.http.HttpObject;

/**
 * 描述:
 *
 * @author 002465
 * @created 2017/7/6 18:40
 * @since v1.0.0
 */
@Service
public class TicketbizServiceImpl implements TicketbizService {

    /**
     * 售票统计
     * @param startDate
     * @param endDate
     * @param type
     * @return
     */
    public  TicketbizResponse<SaleCollectModel> saleCollect(String startDate,String endDate,Integer type){
        TicketbizRequestData data = new TicketbizRequestData(startDate,endDate,type);
        String url = TicketbizProperties.getTicketSaleSumUrl();
        String finalUrl = url +"?data="+ GsonUtil.create().toJson(data);
        String json = HttpObject.getJsonByGet(finalUrl);
        TicketbizResponse<SaleCollectModel> respone = GsonUtil.create().fromJson(json,
                new TypeToken<TicketbizResponse<SaleCollectModel>>() {
                }.getType());
        return respone;
    }

    public  TicketbizResponse<SaleCollectModel> saleCollectByDay(String startDate,String endDate){
        return saleCollect(startDate,endDate,SaleType.DAILY.getCode());
    }

    public  TicketbizResponse<SaleCollectModel> saleCollectByMonth(String startDate,String endDate){
        return saleCollect(startDate,endDate,SaleType.MONTH.getCode());
    }

    @Override
    public TicketbizResponse<SaleCollectModel> saleCollectByYear(String startDate, String endDate) {
        return saleCollect(startDate,endDate,SaleType.YEAR.getCode());
    }
    /**
     * 检票统计
     * @param startDate
     * @param endDate
     * @param type
     * @return
     */
    public  TicketbizResponse<CheckCollectModel> checkCollect(String startDate,String endDate,Integer type){
        TicketbizRequestData data = new TicketbizRequestData(startDate,endDate,type);
        String url = TicketbizProperties.getCheckCollectUrl();
        String finalUrl = url +"?data="+ GsonUtil.create().toJson(data);
        String json = HttpObject.getJsonByGet(finalUrl);
        TicketbizResponse<CheckCollectModel> respone = GsonUtil.create().fromJson(json,
                new TypeToken<TicketbizResponse<CheckCollectModel>>() {
                }.getType());
        return respone;
    }
    public  TicketbizResponse<CheckCollectModel>  checkCollectByDay(String startDate, String endDate){
        return checkCollect(startDate,endDate,SaleType.DAILY.getCode());
    }

    public  TicketbizResponse<CheckCollectModel> checkCollectByMonth(String startDate,String endDate){
        return checkCollect(startDate,endDate,SaleType.MONTH.getCode());
    }

    @Override
    public TicketbizResponse<CheckCollectModel> checkCollectByYear(String startDate, String endDate) {
        return checkCollect(startDate,endDate,SaleType.YEAR.getCode());
    }

    /**
     * 退票统计
     * @param startDate
     * @param endDate
     * @param type
     * @return
     */
    public  TicketbizResponse<ReturnCollectModel> returnCollect(String startDate,String endDate,Integer type){
        TicketbizRequestData data = new TicketbizRequestData(startDate,endDate,type);
        String url = TicketbizProperties.getReturnCollectUrl();
        String finalUrl = url +"?data="+ GsonUtil.create().toJson(data);
        String json = HttpObject.getJsonByGet(finalUrl);
        TicketbizResponse<ReturnCollectModel> respone = GsonUtil.create().fromJson(json,
                new TypeToken<TicketbizResponse<ReturnCollectModel>>() {
                }.getType());
        return respone;
    }
    public TicketbizResponse<ReturnCollectModel> returnCollectByDay(String startDate, String endDate) {
        return returnCollect(startDate,endDate,SaleType.DAILY.getCode());
    }
    public TicketbizResponse<ReturnCollectModel> returnCollectByMonth(String startDate, String endDate) {
        return returnCollect(startDate,endDate,SaleType.MONTH.getCode());
    }
    public TicketbizResponse<ReturnCollectModel> returnCollectByYear(String startDate, String endDate) {
        return returnCollect(startDate,endDate,SaleType.YEAR.getCode());
    }

    /**
     * 出口人数统计接口
     * @param startDate
     * @param endDate
     * @param type
     * @return
     */
    public  TicketbizResponse<ExitPersonCollectModel<ExitPersonCollectModelData>> exitPersonCollect(String startDate, String endDate, Integer type){
        TicketbizRequestData data = new TicketbizRequestData(startDate,endDate,type);
        String url = TicketbizProperties.getExitPersonCountUrl();
        String finalUrl = url +"?data="+ GsonUtil.create().toJson(data);
        String json = HttpObject.getJsonByGet(finalUrl);
        TicketbizResponse<ExitPersonCollectModel<ExitPersonCollectModelData>> respone = GsonUtil.create().fromJson(json,
                new TypeToken<TicketbizResponse<ExitPersonCollectModel<ExitPersonCollectModelData>>>() {
                }.getType());
        return respone;
    }
    public TicketbizResponse<ExitPersonCollectModel<ExitPersonCollectModelData>> exitPersonCollectByDay(String startDate, String endDate) {
        return exitPersonCollect(startDate,endDate,SaleType.DAILY.getCode());
    }
    public TicketbizResponse<ExitPersonCollectModel<ExitPersonCollectModelData>> exitPersonCollectByMonth(String startDate, String endDate) {
        return exitPersonCollect(startDate,endDate,SaleType.MONTH.getCode());
    }
    public TicketbizResponse<ExitPersonCollectModel<ExitPersonCollectModelData>> exitPersonCollectByYear(String startDate, String endDate) {
        return exitPersonCollect(startDate,endDate,SaleType.YEAR.getCode());
    }

    /**
     * 订单来源分析接口
     * @param startDate
     * @param endDate
     * @param type
     * @return
     */
    public  TicketbizResponse<OrderResourceCollectModel> orderResourceCollect(String startDate, String endDate, Integer type){
        TicketbizRequestData data = new TicketbizRequestData(startDate,endDate,type);
        String url = TicketbizProperties.getOrderResourceCollectUrl();
        String finalUrl = url +"?data="+ GsonUtil.create().toJson(data);
        String json = HttpObject.getJsonByGet(finalUrl);
        TicketbizResponse<OrderResourceCollectModel> respone = GsonUtil.create().fromJson(json,
                new TypeToken<TicketbizResponse<OrderResourceCollectModel>>() {
                }.getType());
        return respone;
    }

    public TicketbizResponse<OrderResourceCollectModel> orderResourceCollectByDay(String startDate, String endDate) {
        return orderResourceCollect(startDate,endDate,SaleType.DAILY.getCode());
    }
    public TicketbizResponse<OrderResourceCollectModel> orderResourceCollectByMonth(String startDate, String endDate) {
        return orderResourceCollect(startDate,endDate,SaleType.MONTH.getCode());
    }
    public TicketbizResponse<OrderResourceCollectModel> orderResourceCollectByYear(String startDate, String endDate) {
        return orderResourceCollect(startDate,endDate,SaleType.YEAR.getCode());
    }


    /**
     * 游客购票类型分析接口
     * @param startDate
     * @param endDate
     * @param type
     * @return
     */
    public  TicketbizResponse<TicketTypeCollectModel> ticketTypeCollect(String startDate, String endDate, Integer type){
        TicketbizRequestData data = new TicketbizRequestData(startDate,endDate,type);
        String url = TicketbizProperties.getTicketCollectUrl();
        String finalUrl = url +"?data="+ GsonUtil.create().toJson(data);
        String json = HttpObject.getJsonByGet(finalUrl);
        TicketbizResponse<TicketTypeCollectModel> respone = GsonUtil.create().fromJson(json,
                new TypeToken<TicketbizResponse<TicketTypeCollectModel>>() {
                }.getType());
        return respone;
    }

    public TicketbizResponse<TicketTypeCollectModel> ticketTypeCollectByDay(String startDate, String endDate) {
        return ticketTypeCollect(startDate,endDate,SaleType.DAILY.getCode());
    }
    public TicketbizResponse<TicketTypeCollectModel> ticketTypeCollectByMonth(String startDate, String endDate) {
        return ticketTypeCollect(startDate,endDate,SaleType.MONTH.getCode());
    }
    public TicketbizResponse<TicketTypeCollectModel> ticketTypeCollectByYear(String startDate, String endDate) {
        return ticketTypeCollect(startDate,endDate,SaleType.YEAR.getCode());
    }


    /**
     * 景区免费票数据分析接口
     * @param startDate
     * @param endDate
     * @param type
     * @return
     */
    public  TicketbizResponse<FreeTicketCollectModel> freeTicketCollect(String startDate, String endDate, Integer type){
        TicketbizRequestData data = new TicketbizRequestData(startDate,endDate,type);
        String url = TicketbizProperties.getFreeTicketCollectUrl();
        String finalUrl = url +"?data="+ GsonUtil.create().toJson(data);
        String json = HttpObject.getJsonByGet(finalUrl);
        TicketbizResponse<FreeTicketCollectModel> respone = GsonUtil.create().fromJson(json,
                new TypeToken<TicketbizResponse<FreeTicketCollectModel>>() {
                }.getType());
        return respone;
    }

    public TicketbizResponse<FreeTicketCollectModel> freeTicketCollectByDay(String startDate, String endDate) {
        return freeTicketCollect(startDate,endDate,SaleType.DAILY.getCode());
    }
    public TicketbizResponse<FreeTicketCollectModel> freeTicketCollectByMonth(String startDate, String endDate) {
        return freeTicketCollect(startDate,endDate,SaleType.MONTH.getCode());
    }
    public TicketbizResponse<FreeTicketCollectModel> freeTicketCollectByYear(String startDate, String endDate) {
        return freeTicketCollect(startDate,endDate,SaleType.YEAR.getCode());
    }

    /**
     * 景区免费票数据分析接口
     * @param startDate
     * @param endDate
     * @param type
     * @return
     */
    public  TicketbizResponse<OriginateCollectModel> originateCollect(String startDate, String endDate, Integer type){
        TicketbizRequestData data = new TicketbizRequestData(startDate,endDate,type);
        String url = TicketbizProperties.getOriginateCollectUrl();
        String finalUrl = url +"?data="+ GsonUtil.create().toJson(data);
        String json = HttpObject.getJsonByGet(finalUrl);
        TicketbizResponse<OriginateCollectModel> respone = GsonUtil.create().fromJson(json,
                new TypeToken<TicketbizResponse<OriginateCollectModel>>() {
                }.getType());
        return respone;
    }

    public TicketbizResponse<OriginateCollectModel> originateCollectByDay(String startDate, String endDate) {
        return originateCollect(startDate,endDate,SaleType.DAILY.getCode());
    }
    public TicketbizResponse<OriginateCollectModel> originateCollectByMonth(String startDate, String endDate) {
        return originateCollect(startDate,endDate,SaleType.MONTH.getCode());
    }
    public TicketbizResponse<OriginateCollectModel> originateCollectByYear(String startDate, String endDate) {
        return originateCollect(startDate,endDate,SaleType.YEAR.getCode());
    }

    /**
     * 旅行社销售量统计接口
     * @param startDate
     * @param endDate
     * @param type
     * @return
     */
    public  TicketbizResponse<TravelSalesModel> travelSales(String startDate, String endDate, Integer type){
        TicketbizRequestData data = new TicketbizRequestData(startDate,endDate,type);
        String url = TicketbizProperties.getTravelSalesUrl();
        String finalUrl = url +"?data="+ GsonUtil.create().toJson(data);
        String json = HttpObject.getJsonByGet(finalUrl);
        TicketbizResponse<TravelSalesModel> respone = GsonUtil.create().fromJson(json,
                new TypeToken<TicketbizResponse<TravelSalesModel>>() {
                }.getType());
        return respone;
    }

    public TicketbizResponse<TravelSalesModel> travelSalesByDay(String startDate, String endDate) {
        return travelSales(startDate,endDate,SaleType.DAILY.getCode());
    }
    public TicketbizResponse<TravelSalesModel> travelSalesByMonth(String startDate, String endDate) {
        return travelSales(startDate,endDate,SaleType.MONTH.getCode());
    }
    public TicketbizResponse<TravelSalesModel> travelSalesByYear(String startDate, String endDate) {
        return travelSales(startDate,endDate,SaleType.YEAR.getCode());
    }

}
